package com.example.nbshopping.goods;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.squareup.picasso.Picasso;
import java.util.List;
import com.example.nbshopping.R;
import com.example.nbshopping.utils.URLUtils;
public class GoodsTypeAdapter extends BaseAdapter{
    Context context;
    List<GoodsBean.DataBean> data;
    public GoodsTypeAdapter(Context context, List<GoodsBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }
    @Override
    public int getCount() { return data.size(); }
    @Override
    public GoodsBean.DataBean getItem(int pos) { return data.get(pos); }
    @Override
    public long getItemId(int pos) { return pos; }
    @Override
    public View getView(int pos, View convertView, ViewGroup parent) {
        VH vh= null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_goodstype,parent,false);
            vh = new VH(convertView);
            convertView.setTag(vh);
        }else {
            vh = (VH) convertView.getTag();
        }
        GoodsBean.DataBean dataBean = data.get(pos);
        vh.titleTv.setText(dataBean.getName());
        vh.desTv.setText(dataBean.getInfo());
        vh.priceTv.setText("￥ "+dataBean.getPrice()+"元");
        String photo = dataBean.getPhoto();
        if (!TextUtils.isEmpty(photo)) {
            String photourl = URLUtils.PUBLIC_URL+photo;
            Picasso.with(context).load(photourl).into(vh.iv);
        }
        return convertView;
    }
    class VH{
        TextView titleTv,priceTv,desTv;
        ImageView iv;
        public VH(View v){
            titleTv = v.findViewById(R.id.item_search_goodstype_tv_title);
            priceTv = v.findViewById(R.id.item_goodstype_tv_price);
            desTv = v.findViewById(R.id.item_goodstype_tv_des);
            iv = v.findViewById(R.id.item_search_goodstype_iv);
        }
    }
}